package com.fang.observer;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

/**
 * @author fanglingxiao
 * @version 1.0
 * @description 订单状态变更被观察者
 * @date 2022/4/25 2:41 下午
 **/
public class OrderStatusSubject extends Observable {

    private static final List<Observer> observerList = new ArrayList<>();

    public void attach(Observer observer) {
        observerList.add(observer);
    }

    public void payCallback() {
        System.out.println("支付回调");
        notifyAllObserver("我修改了");
    }

    private void notifyAllObserver(Object obj) {
        observerList.forEach(o -> {
            o.update(this, obj);
        });
//        super.setChanged();
//        super.notifyObservers(obj);
    }
}
